<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Data::Types - Validate and convert data types. - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Data-Types - MetaCPAN" href="https://metacpan.org/dist/Data-Types/releases.rss" />
        <link rel="canonical" href="./Data::Types.html" />
        <meta name="description" content="Validate and convert data types." />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Data::Types" />
<meta name="twitter:title"       content="Data::Types" />
<meta name="twitter:description" content="Validate and convert data types." />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Data::Types.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Data-Types was released.">
      <span class="relatize">23 Feb 2019 12:35:02 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Data-Types">Data-Types</a>
  </li>
  <li>
    Module version: 0.17
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Data-Types/source/lib/Data/Types.pm">Source</a>
    (<a href="https://metacpan.org/dist/Data-Types/source/lib/Data/Types.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Data-Types/source/lib/Data">Browse</a>
    (<a href="https://metacpan.org/dist/Data-Types/source/lib/Data?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Data-Types/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Data-Types/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/manwar/Data-Types">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Types">Issues</a>
      (0)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Data-Types+0.17" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Types.html?oncpan=1&amp;distmat=1&amp;version=0.17&amp;grade=2" style="color: #090">2930</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Types.html?oncpan=1&amp;distmat=1&amp;version=0.17&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Types.html?oncpan=1&amp;distmat=1&amp;version=0.17&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/MANWAR/Data-Types-0.17">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Data-Types who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 2
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Data-Types-0.17/index.html">98.69% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.6.0
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Data-Types/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/M/MA/MANWAR/Data-Types-0.17.tar.gz">
      Download (<span itemprop="fileSize">7.76KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FMANWAR%2FData-Types-0.17%2Flib%2FData%2FTypes.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Data-Types/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Data-Types/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Data-Types">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Data-Types">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Data/Types.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="MANWAR/Data-Types-0.17"
>0.17
  (MANWAR on 2019-02-23)</option>
<option
  
  value="MANWAR/Data-Types-0.16"
>0.16
  (MANWAR on 2018-12-03)</option>
<option
  
  value="MANWAR/Data-Types-0.15"
>0.15
  (MANWAR on 2018-11-19)</option>
<option
  
  value="DWHEELER/Data-Types-0.09"
>0.09
  (DWHEELER on 2011-06-20)</option>
<option
  
  value="DWHEELER/Data-Types-0.08"
>0.08
  (DWHEELER on 2008-05-05)</option>
<option
  
  value="DWHEELER/Data-Types-0.07"
>0.07
  (DWHEELER on 2008-01-22)</option>
<optgroup label="BackPAN">'
<option
  
  value="MANWAR/Data-Types-0.14"
>0.14
  (MANWAR on 2018-10-15)</option>
<option
  
  value="MANWAR/Data-Types-0.13"
>0.13
  (MANWAR on 2018-05-26)</option>
<option
  
  value="MANWAR/Data-Types-0.12"
>0.12
  (MANWAR on 2018-05-25)</option>
<option
  
  value="MANWAR/Data-Types-0.11"
>0.11
  (MANWAR on 2018-05-24)</option>
<option
  
  value="DWHEELER/Data-Types-0.06"
>0.06
  (DWHEELER on 2006-05-23)</option>
<option
  
  value="DWHEELER/Data-Types-0.05"
>0.05
  (DWHEELER on 2003-08-26)</option>
<option
  
  value="DWHEELER/Data-Types-0.04"
>0.04
  (DWHEELER on 2002-07-25)</option>
<option
  
  value="DWHEELER/Data-Types-0.03"
>0.03
  (DWHEELER on 2002-07-22)</option>
<option
  
  value="DWHEELER/Data-Types-0.02"
>0.02
  (DWHEELER on 2002-01-04)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/MANWAR/Data-Types-0.17/diff/' + encodeURIComponent(this.value) + '/lib/Data/Types.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="MANWAR/Data-Types-0.17"
>0.17
  (MANWAR on 2019-02-23)</option>
<option
  
  value="MANWAR/Data-Types-0.16"
>0.16
  (MANWAR on 2018-12-03)</option>
<option
  
  value="MANWAR/Data-Types-0.15"
>0.15
  (MANWAR on 2018-11-19)</option>
<option
  
  value="DWHEELER/Data-Types-0.09"
>0.09
  (DWHEELER on 2011-06-20)</option>
<option
  
  value="DWHEELER/Data-Types-0.08"
>0.08
  (DWHEELER on 2008-05-05)</option>
<option
  
  value="DWHEELER/Data-Types-0.07"
>0.07
  (DWHEELER on 2008-01-22)</option>
<optgroup label="BackPAN">'
<option
  
  value="MANWAR/Data-Types-0.14"
>0.14
  (MANWAR on 2018-10-15)</option>
<option
  
  value="MANWAR/Data-Types-0.13"
>0.13
  (MANWAR on 2018-05-26)</option>
<option
  
  value="MANWAR/Data-Types-0.12"
>0.12
  (MANWAR on 2018-05-25)</option>
<option
  
  value="MANWAR/Data-Types-0.11"
>0.11
  (MANWAR on 2018-05-24)</option>
<option
  
  value="DWHEELER/Data-Types-0.06"
>0.06
  (DWHEELER on 2006-05-23)</option>
<option
  
  value="DWHEELER/Data-Types-0.05"
>0.05
  (DWHEELER on 2003-08-26)</option>
<option
  
  value="DWHEELER/Data-Types-0.04"
>0.04
  (DWHEELER on 2002-07-25)</option>
<option
  
  value="DWHEELER/Data-Types-0.03"
>0.03
  (DWHEELER on 2002-07-22)</option>
<option
  
  value="DWHEELER/Data-Types-0.02"
>0.02
  (DWHEELER on 2002-01-04)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><i class="ttip" title="dynamic_config enabled">unknown</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Data::Types/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Data%3A%3ATypes">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Data-Types">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/MANWAR/Data-Types-0.17/view/lib/Data/Types.pm">This version</a>
    </li>
    <li>
      <a href="./Data::Types.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
    2 non-PAUSE users
</div>
</div>
    </li>
    <li>
<div id="metacpan_contributors">
  <div>
    <button class="btn-link"
      onclick="$(this).hide(); $('#metacpan_contributors ul').slideDown(); return false;"
    >and 1 contributors</button>
  </div>
  <ul style="display: none">
    <li class="contributor"
      data-cpan-author="DWHEELER"
      data-contrib-email="dwheeler@cpan.org"
    >
      <a href="https://metacpan.org/author/DWHEELER" class="cpan-author">
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/de2fe609ec8ae522883ea1235f1e8792?d=identicon&amp;s=20" />
      David E. Wheeler
      </a>
    </li>
  </ul>
</div>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/MANWAR" class="author-name">Mohammad Sajid Anwar</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Data/Types.pm&#39;" class="">
<option
  selected
  value="MANWAR/Data-Types-0.17"
>0.17
  (MANWAR on 2019-02-23)</option>
<option
  
  value="MANWAR/Data-Types-0.16"
>0.16
  (MANWAR on 2018-12-03)</option>
<option
  
  value="MANWAR/Data-Types-0.15"
>0.15
  (MANWAR on 2018-11-19)</option>
<option
  
  value="DWHEELER/Data-Types-0.09"
>0.09
  (DWHEELER on 2011-06-20)</option>
<option
  
  value="DWHEELER/Data-Types-0.08"
>0.08
  (DWHEELER on 2008-05-05)</option>
<option
  
  value="DWHEELER/Data-Types-0.07"
>0.07
  (DWHEELER on 2008-01-22)</option>
<optgroup label="BackPAN">'
<option
  
  value="MANWAR/Data-Types-0.14"
>0.14
  (MANWAR on 2018-10-15)</option>
<option
  
  value="MANWAR/Data-Types-0.13"
>0.13
  (MANWAR on 2018-05-26)</option>
<option
  
  value="MANWAR/Data-Types-0.12"
>0.12
  (MANWAR on 2018-05-25)</option>
<option
  
  value="MANWAR/Data-Types-0.11"
>0.11
  (MANWAR on 2018-05-24)</option>
<option
  
  value="DWHEELER/Data-Types-0.06"
>0.06
  (DWHEELER on 2006-05-23)</option>
<option
  
  value="DWHEELER/Data-Types-0.05"
>0.05
  (DWHEELER on 2003-08-26)</option>
<option
  
  value="DWHEELER/Data-Types-0.04"
>0.04
  (DWHEELER on 2002-07-25)</option>
<option
  
  value="DWHEELER/Data-Types-0.03"
>0.03
  (DWHEELER on 2002-07-22)</option>
<option
  
  value="DWHEELER/Data-Types-0.02"
>0.02
  (DWHEELER on 2002-01-04)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Data-Types">Data-Types-0.17</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage two &#10;
          • 5 direct dependents &#10;          • 10 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Data-Types-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Data-Types-0.17">
    <input type="hidden" name="author" value="MANWAR">
    <input type="hidden" name="distribution" value="Data-Types">
    <button type="submit" class="favorite highlight"><span>2</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Data::Types.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>2</span> ++</a>
</div>
   / <span>Data::Types</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Data::Types.html#NAME">NAME</a></li>
  <li><a href="./Data::Types.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Data::Types.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Data::Types.html#EXPORT">EXPORT</a></li>
  <li><a href="./Data::Types.html#FUNCTIONS">FUNCTIONS</a>
    <ul>
      <li><a href="./Data::Types.html#is_whole">is_whole</a></li>
      <li><a href="./Data::Types.html#to_whole">to_whole</a></li>
      <li><a href="./Data::Types.html#is_count">is_count</a></li>
      <li><a href="./Data::Types.html#to_count">to_count</a></li>
      <li><a href="./Data::Types.html#is_int">is_int</a></li>
      <li><a href="./Data::Types.html#to_int">to_int</a></li>
      <li><a href="./Data::Types.html#is_decimal">is_decimal</a></li>
      <li><a href="./Data::Types.html#to_decimal">to_decimal</a></li>
      <li><a href="./Data::Types.html#is_real">is_real</a></li>
      <li><a href="./Data::Types.html#to_real">to_real</a></li>
      <li><a href="./Data::Types.html#is_float">is_float</a></li>
      <li><a href="./Data::Types.html#to_float">to_float</a></li>
      <li><a href="./Data::Types.html#is_string">is_string</a></li>
      <li><a href="./Data::Types.html#to_string">to_string</a></li>
    </ul>
  </li>
  <li><a href="./Data::Types.html#SUPPORT">SUPPORT</a></li>
  <li><a href="./Data::Types.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Data::Types.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Data::Types.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Data::Types - Validate and convert data types.</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>  use Data::Types qw(:all);

  my $whole = 4.5;
  $whole = to_whole($whole) unless is_whole($whole);

  my $int = 1.2;
  $int = to_int($int) unless is_int($int);

  my $decimal = &#39;1.2foo&#39;;
  $decimal = to_decimal($decimal) unless is_decimal($decimal);

  my $real = &#39;1.2foo&#39;;
  $real = to_real($real) unless is_real($real);

  my $float = &#39;1.2foo&#39;;
  $float = to_float($float) unless is_float($float);

  my $string = [];
  $string = to_string($string) unless is_string($string);</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module exports a number of functions that are useful for validating and converting data types. It is intended for use in applications where data types are more important than they typically are in Perl -- e.g., database applications.</p>

<h1 id="EXPORT">EXPORT</h1>

<p>No functions are exported by default, though each function may be exported explicitly (see <a href="./Data::Types.html#FUNCTIONS">&quot;FUNCTIONS&quot;</a> below, for a list of functions available for export). The following export tags are supported:</p>

<dl>

<dt id=":whole"><a id="whole"></a>:whole</dt>
<dd>

<p>Exports is_whole() and to_whole().</p>

</dd>
<dt id=":count"><a id="count"></a>:count</dt>
<dd>

<p>Exports is_count() and to_count().</p>

</dd>
<dt id=":int"><a id="int"></a>:int</dt>
<dd>

<p>Exports is_int() and to_int().</p>

</dd>
<dt id=":decimal"><a id="decimal"></a>:decimal</dt>
<dd>

<p>Exports is_decimal() and to_decimal().</p>

</dd>
<dt id=":real"><a id="real"></a>:real</dt>
<dd>

<p>Exports is_real() and to_real().</p>

</dd>
<dt id=":float"><a id="float"></a>:float</dt>
<dd>

<p>Exports is_float() and to_float().</p>

</dd>
<dt id=":string"><a id="string"></a>:string</dt>
<dd>

<p>Exports is_string() and to_string().</p>

</dd>
<dt id=":is"><a id="is"></a>:is</dt>
<dd>

<p>Exports all validation functions: is_whole(), is_int(), is_real(), is_decimal(), is_float(), and is_string().</p>

</dd>
<dt id=":to"><a id="to"></a>:to</dt>
<dd>

<p>Exports all conversion functions: to_whole(), to_int(), to_real(), to_decimal(), to_float(), and to_string().</p>

</dd>
<dt id=":all"><a id="all"></a>:all</dt>
<dd>

<p>Exports all functions.</p>

</dd>
</dl>

<h1 id="FUNCTIONS">FUNCTIONS</h1>

<h2 id="is_whole">is_whole</h2>

<pre><code>  my $bool = is_whole($val);</code></pre>

<p>Returns true if $val is a whole number (including 0), and false if it is not. The regular expression used to test the wholeness of $val is <code>/^\d+$/</code>.</p>

<pre><code>  my $bool = is_whole(1); # Returns true.
  $bool = is_whole(-1);   # Returns false.
  $bool = is_whole(0);    # Returns true.</code></pre>

<h2 id="to_whole">to_whole</h2>

<pre><code>  my $whole = to_whole($val);</code></pre>

<p>Converts $val to a whole number and returns it. Numbers will be rounded to the nearest whole. If $val is a mixture of numbers and letters, to_whole() will extract the first decimal number it finds and convert that number to a whole number.</p>

<pre><code>  my $whole = to_whole(10);     # Returns 10.
  $whole = to_whole(0);         # Returns 0.
  $whole = to_whole(.22);       # Returns 0.
  $whole = to_whole(-2);        # Returns undef.
  $whole = to_whole(&#39;foo3.56&#39;); # Returns 4.
  $whole = to_whole(&#39;foo&#39;);     # Returns undef.</code></pre>

<h2 id="is_count">is_count</h2>

<pre><code>  my $bool = is_count($val);</code></pre>

<p>Returns true if $val is a counting number (1, 2, 3, ...), and false if it is not. The regular expression used to test whether $val is a counting number is <code>/^\d+$/</code>.</p>

<pre><code>  my $bool = is_count(1); # Returns true.
  $bool = is_count(-1);   # Returns false.
  $bool = is_count(0);    # Returns false.</code></pre>

<h2 id="to_count">to_count</h2>

<pre><code>  my $count = to_count($val);</code></pre>

<p>Converts $val to a counting number and returns it. Numbers will be rounded to the nearest counting number. Note that since 0 (zero) is not considered a counting number by this module, it will not be returned. If $val is a mixture of numbers and letters, to_count() will extract the first decimal number it finds and convert that number to a counting number.</p>

<pre><code>  my $count = to_count(10);     # Returns 10.
  $count = to_count(0);         # Returns undef.
  $count = to_count(.22);       # Returns undef (rounded down to 0).
  $count = to_count(-2);        # Returns undef.
  $count = to_count(&#39;foo3.56&#39;); # Returns 4.
  $count = to_count(&#39;foo&#39;);     # Returns undef.</code></pre>

<h2 id="is_int">is_int</h2>

<pre><code>  my $bool = is_int($val);</code></pre>

<p>Returns true if $val is an integer, and false if it is not. Numbers may be preceded by a plus or minus sign. The regular expression used to test for an integer in $val is <code>/^[+-]?\d+$/</code>.</p>

<pre><code>  my $bool = is_int(0); # Returns true.
  $bool = is_int(22);   # Returns true.
  $bool = is_int(-22);  # Returns true.
  $bool = is_int(3.2);  # Returns false.</code></pre>

<h2 id="to_int">to_int</h2>

<pre><code>  my $int = to_int($val);</code></pre>

<p>Converts $val to an integer. If $val is a decimal number, it will be rounded to the nearest integer. If $val is a mixture of numbers and letters, to_int() will extract the first decimal number it finds and convert that number to an integer.</p>

<pre><code>  my $int = to_int(10.5);  # Returns 10.
  $int = to_int(10.51);    # Returns 11.
  $int = to_int(-0.22);    # Returns 0.
  $int = to_int(-6.51);    # Returns 7.
  $int = to_int(&#39;foo&#39;);    # Returns undef.</code></pre>

<h2 id="is_decimal">is_decimal</h2>

<pre><code>  my $bool = is_decimal($val);</code></pre>

<p>Returns true if $val is a decimal number, and false if it is not. Numbers may be preceded by a plus or minus sign. The regular expression used to test $val is <code>/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/</code>.</p>

<pre><code>  my $bool = is_decimal(10)    # Returns true.
  $bool = is_decimal(10.8)     # Returns true.
  $bool = is_decimal(-33.48)   # Returns true.
  $bool = is_decimal(1.23e99)  # Returns false.</code></pre>

<h2 id="to_decimal">to_decimal</h2>

<pre><code>  my $dec = to_decimal($val);
  $dec = to_decimal($val, $precision);</code></pre>

<p>Converts $val to a decimal number. The optional second argument sets the precision of the number. The default precision is 5. If $val is a mixture of numbers and letters, to_decimal() will extract the first decimal number it finds.</p>

<pre><code>  my $dec = to_decimal(0);         # Returns 0.00000.
  $dec = to_decimal(10.5);         # Returns 10.5.
  $dec = to_decimal(10.500009);    # Returns 10.50001.
  $dec = to_decimal(10.500009, 7); # Returns 10.5000090.
  $dec = to_decimal(&#39;foo10.3&#39;)     # Returns 10.30000.
  $dec = to_decimal(&#39;foo-4.9&#39;)     # Returns -4.90000.
  $dec = to_decimal(&#39;foo&#39;)         # Returns undef.</code></pre>

<h2 id="is_real">is_real</h2>

<pre><code>  my $bool = is_real($val);</code></pre>

<p>Returns true if $val is a real number, and false if it is not.</p>

<p><b>Note:</b> This function is currently equivalent to is_decimal(), since this module cannot identify non-decimal real numbers (e.g., irrational numbers). This implementation may change in the future.</p>

<h2 id="to_real">to_real</h2>

<pre><code>  my $real = to_real($val);
  $real = to_real($val, $precision);</code></pre>

<p>Converts $val to a real number.</p>

<p><b>Note:</b> Currently, this function is the equivalent of to_decimal(), since this module cannot identify non-decimal real numbers (e.g., irrational numbers). This implementation may change in the future.</p>

<h2 id="is_float">is_float</h2>

<pre><code>  my $bool = is_float($val);</code></pre>

<p>Returns true if $val is a float, and false if it is not. The regular expression used to test $val is <code>/^([+-]?)(?=[0-9]|\.[0-9])[0-9]*(\.[0-9]*)?([Ee]([+-]?[0-9]+))?$/</code>.</p>

<pre><code>  my $bool = is_float(30);   # Returns true.
  $bool = is_float(1.23e99); # Returns true.
  $bool = is_float(&#39;foo&#39;);   # Returns false.</code></pre>

<h2 id="to_float">to_float</h2>

<pre><code>  my $dec = to_float($val);
  $dec = to_float($val, $precision);</code></pre>

<p>Converts $val to a float. The optional second argument sets the precision of the number. The default precision is 5. If $val is a mixture of numbers and letters, to_float() will extract the first float it finds.</p>

<pre><code>  my $float = to_float(1.23);          # Returns 1.23000.
  $float = to_float(1.23e99);          # Returns 1.23000e+99.
  $float = to_float(1.23e99, 1);       # Returns 1.2e+99.
  $float = to_float(&#39;foo-1.23&#39;);       # Returns -1.23000.
  $float = to_float(&#39;ick_1.23e99foo&#39;); # Returns 1.23000e+99.</code></pre>

<h2 id="is_string">is_string</h2>

<pre><code>  my $bool = is_string($val);</code></pre>

<p>Returns true if $val is a string, and false if it is not. All defined non-references are considered strings.</p>

<pre><code>  my $bool = is_string(&#39;foo&#39;); # Returns true.
  $bool = is_string(20001);    # Returns true.
  $bool = is_string([]);       # Returns false.
  $bool = is_string(undef);    # Returns false.</code></pre>

<h2 id="to_string">to_string</h2>

<pre><code>  my $string = to_string($val);
  $string = to_string($val, $length);</code></pre>

<p>Converts $val into a string. If $val is a reference, the string value of the reference will be returned. Such a value may be a memory address, or some other value, if the stringification operator has been overridden for the object stored in $val. If the optional second argument $length is passed, to_string() will truncate the string to that length. If $length is 0 (zero), it will not limit the length of the return string. If $val is undefined, to_string() will return undef.</p>

<pre><code>  my $string = to_string(&#39;foo&#39;);   # Returns &#39;foo&#39;.
  $string = to_string([]);         # Returns &#39;ARRAY(0x101bec14)&#39;.
  $string = to_string(undef);      # Returns undef.
  $string = to_string(&#39;hello&#39;, 4); # Returns &#39;hell&#39;.</code></pre>

<h1 id="SUPPORT">SUPPORT</h1>

<p>This module is stored in an open <a href="http://github.com/manwar/data-types/">GitHub repository</a>. Feel free to fork and contribute!</p>

<p>Please file bug reports via <a href="http://github.com/manwar/data-types/issues/">GitHub Issues</a> or by sending mail to <a href="mailto:bug-Data-Types@rt.cpan.org">bug-Data-Types@rt.cpan.org</a>.</p>

<p>Patches against Class::Meta are welcome. Please send bug reports to &lt;bug-data-types@rt.cpan.org&gt;.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>David E. Wheeler &lt;david@justatheory.com&gt;</p>

<p>Currently maintained by Mohammad S Anwar <code>&lt;mohammad.anwar @ yahoo.com&gt;</code></p>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<p><a href="https://metacpan.org/pod/perlfaq4#How-do-I-determine-whether-a-scalar-is-anumber/whole/integer/float?">perlfaq4</a> lists the most of the regular expressions used to identify the different numeric types used in this module.</p>

<p><a href="https://metacpan.org/pod/String::Checker">String::Checker</a> also does some data type validation.</p>

<p><a href="./String::Scanf.html">String::Scanf</a> reimplements the C <code>sscanf()</code> function in perl, and also does data type validation and conversion.</p>

<p><a href="./Regexp::Common.html">Regexp::Common</a> contains many useful common regular expressions (surprise!), including some that can be used to identify data types.</p>

<p>Arthur Bergman&#39;s <a href="https://metacpan.org/pod/types">types</a> pragma, offers compile-time data types for Perl 5.8.0. The data types include int, float, and string. I highly recommend using this pragma for fast, static data types.</p>

<h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<p>Copyright (c) 2002-2011, David E. Wheeler. Some Rights Reserved.</p>

<p>This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Data::Types, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Data::Types</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Data::Types</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Data::Types.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
